package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.UserLeaveFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created by Administrator on 2018/1/10 0010.
 */
@Api(value = "UserLeave接口", description = "UserLeave接口")
@Controller
@RequestMapping("/userLeave")
public class UserLeaveController {
    @Resource
    private UserLeaveFacade userLeaveFacade;

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    public void saveUser(HttpServletResponse response, @RequestBody String jsonData) {
        String resultId = this.userLeaveFacade.save(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("id", resultId);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @RequestMapping(value = "/getLeaveByUserId.json", method = RequestMethod.POST)
    public void getLeaveByUserId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> result = userLeaveFacade.getLeaveByUserId(jsonParam.getString("userId"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrTimeRespond(result));
    }
}
